import type { Router } from 'vue-router';

import { hasToken, goLogin } from '@/utils/auth';

export default function setupUserLoginInfoGuard(router: Router) {
  router.beforeEach(async (to, from, next) => {
    next();
    if (hasToken() || !to.meta.requiresAuth) {
      next();
    } else {
      goLogin();
    }
  });
}
